<?php
require_once ("../src/db/connectdatabase.php");

function getCardTypes() {
	$con = new ConnectDB();
	
	$tbl = "cardtype";
	$fn = array('cardtypeid', 'cardtyprname', 'cardtypelogo', 'datecreate');
	$condetion = array('isusecardtype' => true);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'datecreate');
}

function int_to_date($int)
{
    $time  = date("d/m/Y", $int);
    return $time;
}

$arrcardtype = getCardTypes();

?>
<style>
.listbanksviewcontent table {
	width: 850px;
	max-width: 850px;
}

table td {
	margin-top: 2px;
	border: 1px solid;
	border-radius: 2px 2px 2px 2px;
}

table td img {
	cursor: pointer;
}

.title {
	text-align: center;
	background-color: #0088cc;
	min-height: 40px;
	-moz-border-radius: 8px 8px 0px 0px;
	-webkit-border-radius: 8px 8px 0px 0px;
	border-radius: 8px 8px 0px 0px;
	color: #FFF;
}

.stylenamebank {
	padding-left: 5px;
	padding-right: 5px;
	width: 350px;
	max-width: 350px;
}

.stylelogobank {
	width: 100px;
	text-align: center;
	max-width: 100px;
}

.styleacctionbank {
	width: 150px;
	text-align: center;
	max-width: 150px;
}

.styledatecreatebank {
	width: 100px;
	max-width: 100px;
	text-align: center;
}

.nameformbank {
	background: url(../images/bg-login.png);
	-moz-border-radius: 2px 2px 2px 2px;
	-webkit-border-radius: 2px 2px 2px 2px;
	border-radius: 2px 2px 2px 2px;
}

.center {
	text-align: center;
}

table tr:hover td {
	background: #FFC;
}

.stylestt {
	width: 70px;
}
</style>
<h3>Quản Lý Danh Sách Loại Thẻ</h3>
<div class="listbanksviewcontent">
	<table>
    	<tr>
        	<th class="stylestt title">STT</th>
        	<th class="stylenamebank title">Tên Loại Thẻ</th>
            <th class="stylelogobank title">Logo</th>
            <th class="styledatecreatebank title">Ngày C.Nhật</th>
            <th class="styleacctionbank title">Chức Năng</th>
        </tr>
        <?php
		if(count($arrcardtype) > 0) {
			$i = 0;
			foreach($arrcardtype as $entry) {
				$i++;
		?>
        <tr>
        	<td class="nameformbank" align="center"><?php echo($i) ?></td>
        	<td class="nameformbank" style="padding-left:5px; padding-right:5px;"><?php echo($entry[1]) ?></td>
            <td class="nameformbank center"><img src="../<?php echo($entry[2]) ?>" /></td>
            <td class="nameformbank center"><?php echo(int_to_date($entry[3])) ?></td>
            <td class="nameformbank center"><img idct="<?php echo($entry[0]) ?>" class="class-editcardtype-link" src="../images/icon-edit.gif" title="Chỉnh Sửa <?php echo($entry[1]) ?>" />&nbsp; | &nbsp;<img idct="<?php echo($entry[0]) ?>" class="class-deletecardtype-link" src="../images/icon-delete.gif" title="Xóa <?php echo($entry[1]) ?>" /></td>
        </tr>
        <?php
			}
		} else {
		?>
        <tr><th colspan="4">Chưa có danh sách loại thẻ nào</th></tr>
        <?php
		}
		?>
    </table>
</div>
<div><a href="admin.php?content=quanlythetindung&&as=addcardtype"><img src="../images/icon-add.jpg" title="Thêm Loại Thẻ" />Thêm Loại Thẻ</a></div>
<script>
	$(document).on('click', '.class-editcardtype-link', function(e) {
		elem = $(this)
		var idcardtype = elem.attr('idct');
		window.location= 'admin.php?content=quanlythetindung&&as=editcardtype&&id=' + idcardtype;
	});
	
	$(document).on('click', '.class-deletecardtype-link', function(e) {
		elem = $(this)
		var idcardtype = elem.attr('idct');
		if(confirm("Bạn có muốn xóa?")) {
			$.ajax({
				url: "../src/ajax/ajaxcardtype.php",
				type: "post",
				data: {act:'del', idre: idcardtype},
				dataType:"json",
				success: function(data) {
					if(data == true) {
						elem.parent().parent().fadeOut(300, function(){elem.parent().parent().remove();});
					} else {
						alert("Cập nhật dữ liệu không thành công, hoặc mất kết nối internet");
					}
				}
			});
		}
	});
</script>